﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SydEnergiPrototype.Model;

namespace SydEnergiPrototype.Logic
{
    public static class Copier
    {
        public static T DeepCopy<T>(T obj)
        {
            T clone;
            List<Type> knownTypes = new List<Type>();
            knownTypes.Add(typeof(Address));
            knownTypes.Add(typeof(MarkedAddress));
            knownTypes.Add(typeof(HistoryEntry));

            var dcs = new DataContractSerializer(typeof(T), knownTypes);
            using(MemoryStream stream = new MemoryStream())
            {
                dcs.WriteObject(stream, obj);
                stream.Position = 0;
                clone = (T) dcs.ReadObject(stream);
            }

            return clone;
        }
    }
}
